package org.hry.netty.heartbeat;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;

public class HeartBeatClientHandler extends SimpleChannelInboundHandler<ByteBuf> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {

    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
//        for (int i = 0; i < 5; i++) {
//            ctx.channel().writeAndFlush("hello\n").addListener((ChannelFutureListener) future -> {
//                if (future.isSuccess()) {
//               TimeUnit.SECONDS.sleep(3);
//                    System.out.println("发送完毕");
//                }
//            });
//        }
//        System.out.println("外部数据发送完毕");
        ByteBuf byteBuf = Unpooled.copiedBuffer("remove|05DCFF393931534D43216944|e7a172e52b50ac6a", StandardCharsets.UTF_8);
        ctx.writeAndFlush(byteBuf);
    }
}
